package com.demo.spring_demo.controller.login;

import com.demo.spring_demo.pojo.Result;
import com.demo.spring_demo.utils.Utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 腾讯云的短信验证码发送的controller
 */
@RestController
@RequestMapping("/sms")
public class SmsController {

    @Autowired
    Utils utils;

    /**
     *  1、注册账户，忘记密码验证码的发送
     * @param email 目标邮箱
     * @param type  类型 register or forgot
     * @return
     */
    @GetMapping("/sendCode/{email}/{type}")
    public Result sendCode(@PathVariable String email, @PathVariable String type) {
        System.out.println(type);
        String smsCode = "";
        try {
            smsCode = utils.getSms(email,type);
            return new Result(200, smsCode, "验证码发送成功");
        } catch (Exception e) {
            return new Result(500, "网络异常");
        }
    }
}
